<template lang="pug">
	.doctor-record-wrap
		.record-filter
			.filter-side(@click="findPatient")
				.filter-option
					.option-title 就诊人
					.arrow-right
				.filter-result {{name}}
			.filter-side(@click="findHospital")
				.filter-option
					.option-title 就诊医院
					.arrow-right
				.filter-result(:class="{grey:hospitalName==='选择查询的医院'}") {{hospitalName}}
		.record-list
			.record-noItem-box(v-if="noItem")
				no-item(text="当前无就诊记录" button="选择医院" @listenClick="findHospital")
			.record-item(v-for="(item,index) in list" :key="index")
				.item-header
					.item-name 诊疗号：{{item.hosflowno_g}}
				.item-content
					.item-left
						.doctor-name
							.name {{item.doc_name}}
							.flag {{item.orderTypeText}}
						.hospital-name {{item.org_name}}
						.department-name {{item.ksmc}}
					.item-right ￥{{item.zfje}}
				.item-footer
					.left 就诊时间：{{item.jzrq}}
					.right(@click="goRecordList(item.hosflowno_g)") 查看详情

</template>

<script>
import noItem from '@/components/no-item'
export default {
	name: 'doctorRecord',
	data() {
		return {
			name: '',
			hospitalName: '选择查询的医院',
			list: [],
			noItem: false
		}
	},
	created() {},
	mounted() {
		this.hospitalName =
			this.wx.getStorageSync('findHospital').orgName || '选择查询的医院'
		this.name = this.wx.getStorageSync('findPatient').name
		this.getRecord()
	},
	onShow() {
		if (this.wx.getStorageSync('isReload').reload) {
			//判断是否需要刷新数据
			this.list = []
			this.noItem = false
			this.hospitalName =
				this.wx.getStorageSync('findHospital').orgName || '选择查询的医院'
			this.name = this.wx.getStorageSync('findPatient').name
			this.wx.setStorage({
				key: 'isReload',
				data: {
					reload: false
				}
			})
			this.getRecord()
		}
	},
	methods: {
		goRecordList(text) {
			this.$router.push({
				path: '/views/doctorRecord/doctorRecordList',
				query: {
					hosflownog: text
				}
			})
		},
		findHospital() {
			this.$router.push({
				path: '/views/doctorRecord/findHospital'
			})
		},
		findPatient() {
			this.$router.push({
				path: '/views/doctorRecord/findPatient'
			})
		},
		getRecord() {
			this.wx.showLoading({
				title: '加载中',
				icon: 'none'
			})

			let findPatient = this.wx.getStorageSync('findPatient')
			let userInfo = this.wx.getStorageSync('userInfo')

			this.api.jtApi
				.doctorRecord({
					access_token: userInfo.accessToken,
					member_num: userInfo.memberNum,
					klx: findPatient.cardType,
					kh: findPatient.cardNumber,
					sjh: findPatient.phone,
					brxm: this.name,
					sfzhm: findPatient.idNumber,
					org_code: this.wx.getStorageSync('findHospital').orgCode,
					status: '00',
					cd_flag: findPatient.yyzt === '02' ? '01' : '00'
				})
				.then(data => {
					this.wx.hideLoading()
					if (data.ret_code === '0') {
						let list = this.tools.formatToArray(data.details.detail)
						list.forEach(item => {
							if (item.order_type === '00') {
								item.orderTypeText = '门诊账单'
							} else if (item.order_type === '01') {
								item.orderTypeText = '住院账单'
							} else if (item.order_type === '02') {
								item.orderTypeText = '挂号账单'
							}
							item.zfje = this.filter.formatIncome(item.zfje)
						})
						this.list = list
					}
					this.noItem = this.list.length <= 0
				})
				.catch(() => {
					this.noItem = this.list.length <= 0
					this.wx.hideLoading()
				})
		}
	},
	components: {
		noItem
	}
}
</script>

<style lang="stylus">
	.doctor-record-wrap
		.record-filter
			display flex
			background-color white
			.filter-side
				font-size 28px
				flex 1
				position relative
				padding mainPadding
				&:first-child:after
					content ''
					position absolute
					top 20px
					bottom 20px
					right 0
					width 2px
					background-color grayBorder
				.filter-option
					display flex
					align-items center
					justify-content space-between
					color grayFontColor88
					padding-bottom 20px
					.arrow-right
						width 16px
						height 24px
						centerBackground("../../assets/image/common/arrow_right_grey.png")
				.filter-result
					&.grey
						color grayFontColor88
		.record-list
			position absolute
			cover()
			top 156px
			bottom 0
			padding-top 20px
			scrollY()
			.record-noItem-box
				position absolute
				z-index 2
				cover()
				center()
			.record-item
				margin-bottom mainMargin
				background-color white
				.item-header
					padding mainPadding 0
					font-size 30px
					.item-name
						color blackFontColor1A
					.state
						text-align right
						min-width 25%
						color #FF4B4B
				.item-content
					background rgba(247,250,255,1)
					padding mainPadding 0
					.item-left
						flex 1
						.doctor-name
							display flex
							align-items center
							.name
								font-size 30px
								font-weight 500
								color blackFontColor1A
								margin-right 12px
							.flag
								color #FDAF3D
								line-height 32px
								padding 0 10px
								background rgba(255,249,239,1)
								border-radius 18px
								border 1px solid rgba(253,175,61,1)
								font-size 20px
								box-sizing border-box
						.hospital-name,.department-name
							font-size 24px
							line-height 34px
							padding-top 18px
							color #aaa
					.item-right
						font-size 32px
						font-weight 600
						color rgba(255,75,75,1)
						line-height 44px
				.item-footer
					padding 18px 0
					.left
						font-size 24px
						color grayFontColor
					.right
						width 152px
						height 56px
						line-height 56px
						border-radius 36px
						border 1px solid rgba(136,136,136,1)
						font-size 26px
						color blackFontColor4C
						box-sizing border-box
						text-align center
				.item-footer,.item-content,.item-header
					display flex
					align-items center
					justify-content space-between
					padding-left mainPadding
					padding-right mainPadding
</style>
